import people.User;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import mysqloperate.*;

public class startpage extends JFrame {
    JFrame jf=this;
    JButton zhu,deng,back;
    public startpage(){
        init();

        Box b1=Box.createVerticalBox();

        //用户名
        Box b21=Box.createHorizontalBox();
        JLabel yonglabel=new JLabel("用户名");
        JTextField yongtext=new JTextField(15);
        b21.add(yonglabel);
        b21.add(Box.createHorizontalStrut(20));
        b21.add(yongtext);

        //密码
        Box b22=Box.createHorizontalBox();
        JLabel mimalabel=new JLabel("密码");
        JPasswordField mimatext=new JPasswordField(15);
        b22.add(mimalabel);
        b22.add(Box.createHorizontalStrut(30));
        b22.add(mimatext);

        //俩按钮
        Box b23=Box.createHorizontalBox();
        deng=new JButton("登 录");
        zhu=new JButton("注 册");
        b23.add(deng);
        b23.add(Box.createHorizontalStrut(30));
        b23.add(zhu);

        deng.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                String zhang=yongtext.getText().trim();
                String mi=new String(mimatext.getPassword());
                if(zhang.equals("")){
                    JOptionPane.showMessageDialog(jf, "请 输 入 账 号","",JOptionPane.WARNING_MESSAGE);
                    return ;
                }
                if(mi.equals("")){
                    JOptionPane.showMessageDialog(jf, "请 输 入 密 码","",JOptionPane.WARNING_MESSAGE);
                    return ;
                }
                //不空后
                User use =new User();
                use.setId(zhang);
                use.setPassword(mi);

                checkuser check=new checkuser(use);
                try {
                    if(check.check()==true){
                        new operatepage(zhang,mi);
                        jf.dispose();
                    }else{
                        JOptionPane.showMessageDialog(jf, "输入账号信息不正确","",JOptionPane.WARNING_MESSAGE);
                        return ;
                    }
                } catch (Exception ex) {
                    throw new RuntimeException(ex);
                }


            }
        });

        zhu.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new registerpage();

            }
        });

        //组装
        b1.add(b21);
        b1.add(Box.createVerticalStrut(40));
        b1.add(b22);
        b1.add(Box.createVerticalStrut(40));
        b1.add(b23);
        Box be=Box.createHorizontalBox();
        back=new JButton("选择学生端");
        b1.add(Box.createVerticalStrut(20));
        be.add(back);
        b1.add(be);

        back.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new realstart();
                jf.dispose();
            }
        });
        add(b1);
        setVisible(true);
    }
    void init(){
        setTitle("学生成绩管理系统教师端");
        setBounds(400,200,400,300);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLayout(new FlowLayout());
        setAlwaysOnTop(true);
        setResizable(false);

        Container con=this.getContentPane();
        con.setBackground(Color.WHITE);


    }
}
